package main

import (
	"fmt"
	"net/http"
	"os"
	"strings"
)

const filePath = "/config/workspace/go-learn/ch01/severXL/static"

func main() {
	http.HandleFunc("/", block)
	http.ListenAndServe("localhost:8000", nil)
}

func block(w http.ResponseWriter, r *http.Request) {
	s := strings.ReplaceAll(r.URL.Path, "/", "")
	fmt.Fprintln(w, string(readFile(s)))
}

func readFile(fileName string) []byte {
	if fileName == "" {
		fileName = "edit.html"
	}
	b, _ := os.ReadFile(filePath + "/" + fileName)
	return b
}
